package info.motteke.kurumi.swt;

import info.motteke.util.MixiVoiceProperties;

import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;

/* package */ class VoiceSashResizeListener extends ControlAdapter {

    private final SashForm sash;

    public VoiceSashResizeListener(SashForm sash) {
        this.sash = sash;
    }

    @Override
    public void controlMoved(ControlEvent controlevent) {
        execEvent(controlevent);
    }


    @Override
    public void controlResized(ControlEvent controlevent) {
        execEvent(controlevent);
    }

    private void execEvent(ControlEvent event) {
        int[] rates = sash.getWeights();
        int total = rates[0] + rates[1];
        int height = rates[0];

        int rate = (height * 100) / total;

        MixiVoiceProperties.getInstance().setWindowTableHeightRate(rate);
    }
}
